package cn.xiaoliu.hrm.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {
    public static final String COURSE_ONLINE_NOTICE_EXCHANGE = "course_online_notice_exchange";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_SMS = "course_online_notice_queue_sms";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_EMAIL = "course_online_notice_queue_email";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_SYSTEM = "course_online_notice_queue_system";

    //定义交换机
    @Bean
    public Exchange createExchange(){
        return ExchangeBuilder.topicExchange(COURSE_ONLINE_NOTICE_EXCHANGE).durable(true).build();
    }
    //创建短信队列
    @Bean
    public Queue smsQueue(){
        return new Queue(COURSE_ONLINE_NOTICE_QUEUE_SMS,true);
    }
    //创建邮件队列
    @Bean
    public Queue emailQueue(){
        return new Queue(COURSE_ONLINE_NOTICE_QUEUE_EMAIL,true);
    }
    //创建系统队列
    @Bean
    public Queue systemQueue(){
        return new Queue(COURSE_ONLINE_NOTICE_QUEUE_SYSTEM,true);
    }

    //绑定队列到交换机
    @Bean
    public Binding smsQueueBinding(){
        return BindingBuilder.bind(smsQueue()).to(createExchange()).with("message.sms").noargs();
    }
    @Bean
    public Binding emailQueueBinding(){
        return BindingBuilder.bind(emailQueue()).to(createExchange()).with("message.email").noargs();
    }
    @Bean
    public Binding systemQueueBinding(){
        return BindingBuilder.bind(systemQueue()).to(createExchange()).with("message.system").noargs();
    }
}
